﻿using DemoQLKhoSX.Library;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace DemoQLKhoSX.DatabaseAccessLayer
{
  public class NhapDAO
    {
        private DBConnection conn;

        public NhapDAO()
        {
            conn = new DBConnection();
        }

        public DataTable searchByID(string id)
        {
            string query = string.Format("select * from TBL_Nhap where IDNhap = @id");
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@id", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(id);
            return conn.executeSelectQuery(query, sqlParameters);
        }
        public bool addNhap(string idnhap, string idthukho, string idncc,string idhang, DateTime ngaynhap, int soluongnhap)
        {
            string query = string.Format("insert into TBL_Nhap values(@idnhap,@idthukho,@idncc,@idhang,@ngaynhap,@soluongnhap)");
            SqlParameter[] sqlParameters = new SqlParameter[6];
            sqlParameters[0] = new SqlParameter("@idnhap", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(idnhap);
            sqlParameters[1] = new SqlParameter("@idthukho", SqlDbType.VarChar);
            sqlParameters[1].Value = Convert.ToString(idthukho);
            sqlParameters[2] = new SqlParameter("@idncc", SqlDbType.VarChar);
            sqlParameters[2].Value = Convert.ToString(idncc);
            sqlParameters[3] = new SqlParameter("@idhang", SqlDbType.VarChar);
            sqlParameters[3].Value = Convert.ToString(idhang);
            sqlParameters[4] = new SqlParameter("@ngaynhap", SqlDbType.DateTime);
            sqlParameters[4].Value = Convert.ToString(ngaynhap);
            sqlParameters[5] = new SqlParameter("@soluongnhap", SqlDbType.Int);
            sqlParameters[5].Value = Convert.ToString(soluongnhap);
            return conn.executeInsertQuery(query, sqlParameters);
        }
    }
}
